﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SOWY.common;

namespace SOWY
{
    class DateFormatter
    {
        private string unformattedString;

        public DateFormatter()
        {
            unformattedString = "";
        }
        public DateFormatter(string input)
        {
            unformattedString = input.ToLower();
        }

        public string formatDate()
        {
            unformattedString = formatThis();
            return unformattedString;
        }

        private string formatThis()
        {
            DateTime tempDate = DateTime.Now;
            try
            {
                if (unformattedString.ToLower().Contains("this day"))
                {
                    unformattedString = unformattedString.Replace("this day", tempDate.DayOfWeek.ToString().ToLower());
                }
                if (unformattedString.ToLower().Contains("today"))
                {
                    unformattedString = unformattedString.Replace("today", tempDate.DayOfWeek.ToString().ToLower());
                }
                if (unformattedString.ToLower().Contains("this month"))
                {
                    unformattedString = unformattedString.Replace("this month", getMonthFromNum(tempDate.Month));
                }
                if (unformattedString.ToLower().Contains("this year"))
                {
                    unformattedString = unformattedString.Replace("this year", tempDate.Year.ToString().ToLower());
                }
            }catch(Exception e)
            {
                return e.ToString();
            }

            return unformattedString;
        }
        private string getMonthFromNum(int input)
        {
            switch (input)
            {
                case 1: return GeneralConstant.MONTH_LONG_JANUARY.ToLower();
                case 2: return GeneralConstant.MONTH_LONG_FEBRUARY.ToLower();
                case 3: return GeneralConstant.MONTH_LONG_MARCH.ToLower();
                case 4: return GeneralConstant.MONTH_LONG_APRIL.ToLower();
                case 5: return GeneralConstant.MONTH_LONG_MAY.ToLower();
                case 6: return GeneralConstant.MONTH_LONG_JUNE.ToLower();
                case 7: return GeneralConstant.MONTH_LONG_JULY.ToLower();
                case 8: return GeneralConstant.MONTH_LONG_AUGUST.ToLower();
                case 9: return GeneralConstant.MONTH_LONG_SEPTEMBER.ToLower();
                case 10: return GeneralConstant.MONTH_LONG_OCTOBER.ToLower();
                case 11: return GeneralConstant.MONTH_LONG_NOVEMBER.ToLower();
                case 12: return GeneralConstant.MONTH_LONG_DECEMBER.ToLower();
                default: return "";
            }
        }
    }
}
